from sqlalchemy import Column, Integer, String, ForeignKey
from sqlalchemy.orm import relationship

from sqlalchemy_tool.model import Model

class CategoryInfo(Model):
    """类别信息"""
    __tablename__ = 'category_info'
    name = Column(String(50), comment='名称', unique=True, nullable=False)
    icon = Column(String(250), comment='图标', nullable=True)
    description = Column(String(250), comment='描述', nullable=True)
    source_name = Column(String(50), comment='源名称', unique=False, nullable=True)
    source_href = Column(String(250), comment='源链接', nullable=True)
    type_list = relationship('TypeInfo', lazy="dynamic")

    def __repr__(self):
        return self.name


class TypeInfo(Model):
    """分类信息"""
    __tablename__ = 'type_info'
    name = Column(String(50), comment='名称', unique=False, nullable=False)
    category_info = Column(Integer, ForeignKey("category_info.id"), comment='类别信息')
    icon = Column(String(250), comment='图标', nullable=True)
    description = Column(String(250), comment='描述', nullable=True)
    source_name = Column(String(50), comment='源名称', unique=False, nullable=True)
    source_href = Column(String(250), comment='源链接', nullable=True)

    category = relationship("CategoryInfo", overlaps='type_list')

    def __repr__(self):
        return self.name
